package cn.itcast.lesson01;


/**
 * 反射的基本概念
 */
public class Main {
	
	
	public static void main(String[] args) throws ClassNotFoundException {
		
		String str1 = "abc";
		
		Class<?> cls1 = str1.getClass();
		Class<?> cls2 = String.class;
		Class<?> cls3 = Class.forName("java.lang.String");
		
		System.out.println("cls1 == cls2 : "+ (cls1 == cls2));
		System.out.println("cls1 == cls3 : "+ (cls1 == cls3));
		
		//3个引用对象指向同1份类的字节码。因为jvm中只会有1份字节码。一旦有了字节码，以后如果要用它，那么永远就是它
		//1份字节码可以搞出多个实例对象来
		
		
		//9大原始类型（基本类型）： boolean, byte, char, short, int, long, float, double, void
		System.out.println("String: "+cls1.isPrimitive());
		
		System.out.println("int: "+ int.class.isPrimitive());
		
		System.out.println("void: "+void.class.isPrimitive());
		
		//int 和 Integer各有各的字节码
		System.out.println("int.class == Integer.class : "+ (int.class == Integer.class));
		
		//Integer.TYPE 表示代表Integer的基本类型的字节码
		System.out.println("int.class == Integer.TYPE : "+ (int.class == Integer.TYPE));
		
		System.out.println("int[].class.isPrimitive(): "+ (int[].class.isPrimitive()));
		System.out.println("int[].class.isArray(): "+ (int[].class.isArray()));
		
	}

}
